package com.cskaoyan.controller;

import com.cskaoyan.bean.BaseRespVo;
import com.cskaoyan.bean.brand.bo.BrandCreateBO;
import com.cskaoyan.bean.brand.vo.BrandCreateDataVO;
import com.cskaoyan.bean.brand.vo.BrandCreateVO;
import com.cskaoyan.bean.param.BaseParam;
import com.cskaoyan.bean.po.MarketBrand;
import com.cskaoyan.service.BrandService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author chenai
 * @description TODO
 * @date 2022-06-05 13:52
 */
@RestController
@RequestMapping("admin/brand")
public class BrandController {
    @Autowired
    BrandService brandService;

    //http://localhost:8083/admin/brand/list?page=1&limit=20&id=1046054&name=1&sort=add_time&order=desc
    //response=BrandListVo
    @RequestMapping("list")
    public BaseRespVo list(BaseParam baseParam, String id, String name) {
        return BaseRespVo.ok(brandService.list(baseParam, id, name));
    }
    //http://localhost:8083/admin/brand/create
    //response=BrandCreateVo
    @RequestMapping("create")
    public BaseRespVo create(@RequestBody() BrandCreateBO brandCreateBO) {
        return BaseRespVo.ok(brandService.create(brandCreateBO));
    }

    //http://localhost:8083/admin/brand/update
    //response=BrandUpdateVo
    @RequestMapping("update")
    public BaseRespVo update(@RequestBody() BrandCreateDataVO brandCreateDataVO) {
        brandCreateDataVO = brandService.update(brandCreateDataVO);
        return BaseRespVo.ok(brandCreateDataVO);
    }

    //http://localhost:8083/admin/brand/delete
    //response=BrandDeleteVo
    @RequestMapping("delete")
    public BaseRespVo delete(@RequestBody() MarketBrand marketBrand) {
        brandService.delete(marketBrand);
        return BaseRespVo.ok();
    }
}
